#include "stdafx.h"
#include "resource.h"
#include "PdfTools2.h"
#include "dlldatax.h"


class CPdfToolsModule : public CAtlDllModuleT< CPdfToolsModule >
{
public :
	DECLARE_LIBID(LIBID_PdfTools)
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_PDFTOOLS2, "{64CDAF5C-EE28-49E1-8906-21406218320B}")
};

CPdfToolsModule _AtlModule;

extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
{
#ifdef _MERGE_PROXYSTUB
    if ( !PrxDllMain(instance, reason, reserved) )
        return FALSE;
#endif
	instance;
    return _AtlModule.DllMain(reason, reserved); 
}

STDAPI DllCanUnloadNow()
{
#ifdef _MERGE_PROXYSTUB
    HRESULT hr = PrxDllCanUnloadNow();
    if ( hr != S_OK )
        return hr;
#endif
    return _AtlModule.DllCanUnloadNow();
}

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
#ifdef _MERGE_PROXYSTUB
    if ( PrxDllGetClassObject(rclsid, riid, ppv) == S_OK )
        return S_OK;
#endif
    return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}

STDAPI DllRegisterServer()
{
    HRESULT hr = _AtlModule.DllRegisterServer();
#ifdef _MERGE_PROXYSTUB
    if ( FAILED(hr) )
        return hr;
    hr = PrxDllRegisterServer();
#endif
	return hr;
}

STDAPI DllUnregisterServer(void)
{
	HRESULT hr = _AtlModule.DllUnregisterServer();
#ifdef _MERGE_PROXYSTUB
    if ( FAILED(hr) )
        return hr;
    hr = PrxDllRegisterServer();
    if ( FAILED(hr) )
        return hr;
    hr = PrxDllUnregisterServer();
#endif
	return hr;
}